﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Registor2009
{
    public partial class ConfigureForm : Form
    {
        public ConfigureForm(Form1 form)
        {
            InitializeComponent();
            this.Icon = new Icon("Icon1.ico");
            this.form = form;

            ds.ReadXml("XMLFile1.xml");
            int tableCount = ds.Tables.Count;
            for(int i=1;i<tableCount;i++){
                dataGridView1.Rows.Add(ds.Tables[i].Rows[0].ItemArray);
            }
            name1.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
            password1.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();

            dsDay.ReadXml("RegistorDay.xml");
            dataGridView2.Rows.Add(dsDay.Tables[0].Rows[0].ItemArray);

        }

        public string getName(){
            return this.name1.Text;
        }

        public string getPassword()
        {
            return this.password1.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for(int i=1;i<ds.Tables.Count;i++){
                int j = dataGridView1.Rows[i-1].Cells.Count;
                object[] obj = new object[j];
                for (int k = 0; k < j; k++)
                {
                    obj[k] = dataGridView1.Rows[i-1].Cells[k].Value;
                }
                ds.Tables[i].Rows[0].ItemArray = obj;
            }

            object[] up = { name1.Text, password1.Text };
            ds.Tables[0].Rows[0].ItemArray = up;
            ds.WriteXml("XMLFile1.xml");

            int count = dataGridView2.Rows[0].Cells.Count;
            object[] obj1 = new object[count];
            for (int i = 0; i < count; i++)
            {
                obj1[i] = dataGridView2.Rows[0].Cells[i].Value;
            }
            dsDay.Tables[0].Rows[0].ItemArray = obj1;
            dsDay.WriteXml("RegistorDay.xml");
            this.Close();
        }

        private void ConfigureForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            dispose();
        }

        private void dispose()
        {
            form.configForm = null;
            form.loadConfig();
        }

        private Form1 form;
        DataSet ds = new DataSet();
        DataSet dsDay = new DataSet();
    }
}
